#!/usr/bin/env bash
# Nmap scanner and report generation
# $1 - IP range
# $2 - report name

# Set script_dir
script_dir="$(dirname "$(realpath "$0")")"

# Source util function
source "${script_dir}/_util"

[ -x "$(command -v nmap)" ] || error_msg "nmap not installed!" 1
[ -x "$(command -v xsltproc)" ] || error_msg "xsltproc not installed!" 1

[[ -n $1 ]] && ip_range=$1 || ip_range="192.168.1.0/24"
[[ -n $2 ]] && scan_name=$2 || scan_name=nmap_scan

info_msg "IP range: $ip_range"
info_msg "Scan name: $scan_name"

nmap -sTV -A -oX $scan_name.xml --webxml $ip_range && xsltproc $scan_name.xml -o $scan_name.html && rm $scan_name.xml
